package cn.iocoder.yudao.module.nginxui.dal.dataobject.config;

import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
import lombok.*;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;

/**
 * Nginx主配置 DO
 *
 * @author HuangJunZhong
 */
@TableName("nginxui_config")
@KeySequence("nginxui_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库，可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class NginxConfigDO extends TenantBaseDO {

    /**
     * 主键
     */
    @TableId
    private Long id;
    /**
     * 配置名称
     */
    private String name;
    /**
     * 配置描述
     */
    private String description;
    /**
     * 工作进程数
     */
    private String workerProcesses;
    /**
     * 最大连接数
     */
    private Integer workerConnections;
    /**
     * 错误日志路径
     */
    private String errorLog;
    /**
     * PID文件路径
     */
    private String pid;
    /**
     * HTTP块包含的其他配置
     */
    private String httpInclude;
    /**
     * 全局包含的其他配置
     */
    private String globalInclude;
    /**
     * 状态(0-草稿,1-已启用,2-已禁用)
     */
    private Integer status;
    /**
     * 完整配置内容
     */
    private String content;

    /**
     * 获取默认的Nginx配置内容
     */
    public static String getDefaultContent() {
        return "worker_processes auto;\n" +
                "error_log /var/log/nginx/error.log warn;\n" +
                "pid /var/run/nginx.pid;\n" +
                "\n" +
                "events {\n" +
                "    worker_connections 1024;\n" +
                "}\n" +
                "\n" +
                "http {\n" +
                "    include /etc/nginx/mime.types;\n" +
                "    default_type application/octet-stream;\n" +
                "    \n" +
                "    log_format main '$remote_addr - $remote_user [$time_local] \"$request\" '\n" +
                "                  '$status $body_bytes_sent \"$http_referer\" '\n" +
                "                  '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n" +
                "    \n" +
                "    access_log /var/log/nginx/access.log main;\n" +
                "    \n" +
                "    sendfile on;\n" +
                "    #tcp_nopush on;\n" +
                "    \n" +
                "    keepalive_timeout 65;\n" +
                "    \n" +
                "    #gzip on;\n" +
                "    \n" +
                "    include /etc/nginx/conf.d/*.conf;\n" +
                "}";
    }

}
